const Category = require('../../models/product/category.model');
const Brand = require('../../models/product/brand.model');
const sendResponse = require('../../utils/response');

// 获取某个分类下的品牌数据
exports.getCategoryBrand = async (req, res, next) => {
  try{
    const { categoryId } = req.params;
    
    // 获取分类品牌
    const categoryBrand = await Category.findOne({
      where: { id: categoryId },
      as: 'Categorys',
      include: [{
        model: Brand,
        as: 'Brands',
        attributes: ['id', 'tmName', 'logoUrl'],
        through: { attributes: [] }, // 如果不想要中间表的属性
      }],
      distinct: true, // 确保正确计数主模型
    });
    
    return sendResponse(res, { data: categoryBrand.Brands });
  } catch (error) {
    next(error)
  }
}